package com.huwei.modules.base.shiro;

import java.util.Map;

import org.apache.shiro.authc.AuthenticationToken;

import com.huwei.modules.base.constant.SystemConstant;
import com.huwei.modules.base.util.BeanUtil;
import com.huwei.modules.base.util.jwt.JwtUtil;
import com.huwei.modules.base.util.jwt.Token;

import lombok.Data;

@Data
public class JwtShiroToken implements AuthenticationToken{
	private static final long serialVersionUID = 1L;
	private Token token;
	private Map<String ,String> principal;
	
	@SuppressWarnings("unchecked")
	public JwtShiroToken(String token) {
		this.token = JwtUtil.definedUtil().parse(token, SystemConstant.secret());
		this.principal = this.token == null ? null : BeanUtil.toBean(this.token.getPlayload().getSub(),Map.class);
	}

	public Object getPrincipal() {
		return this.principal;
	}

	public Object getCredentials() {
		return this.token;
	}

}
